package cn.maydaymemory.maydaycore.command;

import cn.maydaymemory.maydaycore.annotation.CommandHandler;
import cn.maydaymemory.maydaycore.annotation.SubCommandStructureHandler;
import cn.maydaymemory.maydaycore.command.api.CommandStructure;
import cn.maydaymemory.maydaycore.message.util.NeatText;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

public class Example extends CommandStructure {

    @CommandHandler(playerOnly = false,
                    name = "example1",
                    permission = "maydaycore.example1",
                    description = "Just an example.",
                    parameters = {})
    public void example1(){
        sender.sendMessage("You executed example1");
    }

    @CommandHandler(playerOnly = true,
                    name = "example2",
                    permission = "maydaycore.example2",
                    description = "Just an example.并且这是一个中文的description，啊哈哈哈",
                    parameters = {"[target]"})
    public void example2(){
        Player target = Bukkit.getPlayer(args[0]);
        if(target!=null){
            target.setHealth(0);
            player.sendMessage("You killed "+args[0]);
        }else{
            player.sendMessage("Target not found.");
        }
    }

    @CommandHandler(playerOnly = true,
                    name = "example2",
                    permission = "maydaycore.example2",
                    description = "Just an example,and this example is longer,233.",
                    parameters = {})
    public void example2_fix(){
        player.setHealth(0);
        player.sendMessage("You killed yourself.");
    }

    @CommandHandler(name = "example2",
                    permission = "maydaycore.example2",
                    parameters = {"[abc]","{def}"})
    public void test(){
        NeatText neatText = new NeatText();
        neatText.addText("              §a§l才见乔叶绿，复闻杜鹃鸣。",true);
        neatText.addText("§aThis is a test of English sentence,§e in order to ensure that the format is neat, §cI input this text to check whether the length of English is equal to that of Chinese.",true);
        neatText.addText("§7这是一个测试用的句子，是为了检查段落长度是否大致符合要求。",true);
        neatText.addText("§4Yours, MayDayMemory.",false);
        neatText.width(60);
        for(String text:neatText.getTexts("   ")){
            sender.sendMessage(text);
        }
    }

    @SubCommandStructureHandler(name = "child",
                                description = "Just a child.",
                                prefix = "/MaydayCore child ")
    public CommandStructure child(){
        CommandStructure child =new Child();
        return child;
    }

    @Override
    protected void access() {

    }
}
